package com.wendy.controller;

import com.wendy.utils.ResponseUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhuwending
 */
@Controller
@RequestMapping(value = "/page")
public class PageController {

    @GetMapping(value = "/404")
    public String page404() {
        return "error/404";
    }

    @GetMapping(value = "/403")
    public String page403() {
        return "error/403";
    }

    @GetMapping(value = "/500")
    public String page500() {
        return "error/500";
    }

    @RequestMapping(value = "/login")
    @ResponseBody
    public Object login(HttpServletRequest request) {
        String header = request.getHeader("X-Requested-With");
        boolean isAjax = StringUtils.isNotEmpty(header) && "XMLHttpRequest".equalsIgnoreCase(header);
        if (isAjax) {
            return ResponseUtil.errorResponse("登录失效，请重新登录");
        }
        return new ModelAndView("/login");
    }

    @GetMapping(value = "/index")
    public String index() {
        return "index";
    }

    @GetMapping(value = "/")
    public String main() {
        return "";
    }

    @GetMapping(value = "/userInfo")
    public String userInfo() {
        return "userInfo";
    }

    @GetMapping(value = "/console")
    public String console() {
        return "console";
    }

    @GetMapping(value = "/menu")
    public String menu() {
        return "menu";
    }
}
